import {NativeModules} from 'react-native';

export const getVersion = () => {
  return NativeModules.AppModule.getVersion();
};
/**
 * @param {string} version1
 * @param {string} version2
 * @return {number}
 */
export var compareVersion = function (version1: string, version2: string) {
  const arr1 = version1.split('.').map(item => {
    return item.replace(/^0+/, '');
  });
  const arr2 = version2.split('.').map(item => {
    return item.replace(/^0+/, '');
  });
  const Max = Math.max(arr1.length, arr2.length);
  for (let p = 0; p < Max; p++) {
    if ((+arr1[p] || 0) > (+arr2[p] || 0)) {
      return 1;
    } else if ((+arr1[p] || 0) < (+arr2[p] || 0)) {
      return -1;
    }
  }
  return 0;
};
